package io.gitee.twoke.generator.engine.impl.db;

import java.util.Collections;
import java.util.List;

public class GenerateVersion {

  protected String mainVersion;
  protected List<String> alternativeVersionStrings;

  public GenerateVersion(String mainVersion) {
    this.mainVersion = mainVersion;
    this.alternativeVersionStrings = Collections.singletonList(mainVersion);
  }

  public GenerateVersion(String mainVersion, List<String> alternativeVersionStrings) {
    this.mainVersion = mainVersion;
    this.alternativeVersionStrings = alternativeVersionStrings;
  }

  public String getMainVersion() {
    return mainVersion;
  }

  public boolean matches(String version) {
    if (version.equals(mainVersion)) {
      return true;
    } else if (!alternativeVersionStrings.isEmpty()) {
      return alternativeVersionStrings.contains(version);
    } else {
      return false;
    }
  }

  public boolean equals(Object obj) {
    if (!(obj instanceof GenerateVersion)) {
      return false;
    }
    GenerateVersion other = (GenerateVersion) obj;
    boolean mainVersionEqual = mainVersion.equals(other.mainVersion);
    if (!mainVersionEqual) {
      return false;
    } else {
      if (alternativeVersionStrings != null) {
        return alternativeVersionStrings.equals(other.alternativeVersionStrings);
      } else {
        return other.alternativeVersionStrings == null;
      }
    }
  }

}